package com.googlecode.ws.tester.xor.engine;

import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;

import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 * User: pablo
 * Date: 2009-06-08
 * Time: 20:20:11
 */
public class Parser {

    private Object result;

    public Parser(Config config) {
        File f = new File("SprEzService.wsdl");
        try {
            parse(f, config);
        } catch (ParserConfigurationException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (SAXException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }

    public void parse(File f, Config config) throws ParserConfigurationException, SAXException, IOException {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setValidating(false);
        spf.setNamespaceAware(true);
        SAXParser parser = spf.newSAXParser();
        SAXEventHandler saxEventHandler = new SAXEventHandler();
        saxEventHandler.setConfig(config);
        parser.parse(f, saxEventHandler);
        result = saxEventHandler.getRoot();
    }

    public static void main(String[] args) {
        new Parser(new Config());
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }
}
